package com.zcsy.manage.service.system.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zcsy.manage.model.system.App;
import com.zcsy.manage.persistence.system.AppDao;
import com.zcsy.manage.service.system.IAppService;

/**
 * @Project: service
 * @Title: AppServiceImpl
 * @Package com.zcsy.manage.service.system.impl
 * @Description:app版本管理相关服务层实现类
 * @author fangli Fanglwj520@163.com
 * @date 2016年5月13日 下午3:07:44
 * @Copyright：2014 武汉恒数利通软件有限公司 All rights reserved.
 * @version 1.0
 */
@Service
public class AppServiceImpl implements IAppService{
	
    @Autowired
    private AppDao appDao;

    @Override
    public List<App> getAll() {
        return appDao.getAll();
    }

    @Override
    public int updateAppInfo(App app) {
    	App oldApp = appDao.selectByPrimaryKey(app.getId());
    	
    	oldApp.setVersionNo(app.getVersionNo());
    	oldApp.setType(app.getType());
    	oldApp.setUpdateContent(app.getUpdateContent());
    	oldApp.setUploadTime(app.getUploadTime());
    	
        return appDao.updateApp(oldApp);
    }

    @Override
    public int deleteAppInfo(String id) {
        return appDao.deleteApp(id);
    }

    @Override
    public App selectByPrimaryKey(String id) {
        return appDao.selectByPrimaryKey(id);
    }

    @Override
    public List<App> selectApp(App app) {
        return appDao.selectApp(app);
    }

    @Override
    public int insert(App app) {
        return appDao.insertApp(app);
    }

    @Override
    public boolean selectAppIfExists(String versionNo, String type) {
        Map<String , Object> map = new HashMap<String, Object>();
        map.put("versionNo", versionNo);
        map.put("type", type);
        return appDao.getAppInfoByVersionNo(map) != null;
    }
       
    @Override
    public App getAppInfoByType(Integer type) {
        return appDao.getAppInfoByType(type);
    }
}
